package com.ruoyi.park.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.park.domain.MaInOutRecord;
import com.ruoyi.park.service.IMaInOutRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 出入库记录Controller
 *
 * @author cjie
 * @date 2021-09-16
 */
@Api(tags = " 出入库记录")
@RestController
@RequestMapping("/maInOutRecord")
public class MaInOutRecordController extends BaseController {
    @Autowired
    private IMaInOutRecordService maInOutRecordService;

    /**
     * 查询出入库记录列表
     */
    @ApiOperation(value="查询出入库记录列表", notes="查询出入库记录列表")
    @PreAuthorize(hasPermi = "park:maInOutRecord:list")
    @GetMapping("/list")
    public TableDataInfo list(MaInOutRecord maInOutRecord) {
        startPage();
        List<MaInOutRecord> list = maInOutRecordService.selectMaInOutRecordList(maInOutRecord);
        return getDataTable(list);
    }

    /**
     * 导出出入库记录列表
     */
    @ApiOperation(value="导出出入库记录列表", notes="导出出入库记录列表")
    @PreAuthorize(hasPermi = "park:maInOutRecord:export")
    @Log(title = "出入库记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MaInOutRecord maInOutRecord) throws IOException {
        List<MaInOutRecord> list = maInOutRecordService.selectMaInOutRecordList(maInOutRecord);
        ExcelUtil<MaInOutRecord> util = new ExcelUtil<MaInOutRecord>(MaInOutRecord.class);
        util.exportExcel(response, list, "出入库记录数据");
    }
    /**
     * 获取出入库记录详细信息
     */
    @ApiOperation(value="获取出入库记录详细信息", notes="获取出入库记录详细信息")
    @PreAuthorize(hasPermi = "park:maInOutRecord:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(maInOutRecordService.selectMaInOutRecordById(id));
    }

    /**
     * 新增出入库记录
     */
    @ApiOperation(value="新增出入库记录", notes="新增出入库记录")
    @PreAuthorize(hasPermi = "park:maInOutRecord:add")
    @Log(title = "出入库记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MaInOutRecord maInOutRecord) {
        return maInOutRecordService.insertMaInOutRecord(maInOutRecord);
    }

    /**
     * 修改出入库记录
     */
    @ApiOperation(value="修改出入库记录", notes="修改出入库记录")
    @PreAuthorize(hasPermi = "park:maInOutRecord:edit")
    @Log(title = "出入库记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MaInOutRecord maInOutRecord) {
        return toAjax(maInOutRecordService.updateMaInOutRecord(maInOutRecord));
    }

    /**
     * 删除出入库记录
     */
    @ApiOperation(value="删除出入库记录", notes="删除出入库记录")
    @ApiImplicitParam(name = "ids", value = "出入库记录ID数组", required = true,paramType = "path", allowMultiple=true, dataType = "String")
    @PreAuthorize(hasPermi = "park:maInOutRecord:remove")
    @Log(title = "出入库记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(maInOutRecordService.deleteMaInOutRecordByIds(ids));
    }
}
